<template>
    <div class="form">
        <el-form label-width="auto" :rules="formRules" ref="formRef" :model="placeInfo">
            <el-form-item label="停车场编号" prop="parkingNum">
                <el-input type="tel" v-model="placeInfo.parkingNum" placeholder="请输入"></el-input>
            </el-form-item>
            <el-form-item label="车位编号" prop="spaceNum">
                <el-input type="tel" v-model="placeInfo.spaceNum" placeholder="请输入"></el-input>
            </el-form-item>
            <el-form-item label="面积" prop="area">
                <el-input type="tel" v-model="placeInfo.area" placeholder="请输入"></el-input>
            </el-form-item>
            <el-form-item lable="创建时间">
                <div class="block">
                    <span class="demonstration">创建时间</span>
                    <el-date-picker v-model="placeInfo.createTime" type="date" placeholder="Pick a day" :size="size" />
                </div>
            </el-form-item>
            <el-form-item label="备注">
                <el-input type="textarea" v-model="placeInfo.notes" style="width: 400px" :rows="6"
                    placeholder="请输入备注"></el-input>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="save(formRef)">保存</el-button>
                <el-button type="info" @click="cancel">取消</el-button>
            </el-form-item>
        </el-form>
    </div>

</template>
<script setup>
import http from '../utils/http'
import { ref } from 'vue'
import { ElMessageBox } from 'element-plus'
import { useRouter } from 'vue-router';
import { onBeforeMount } from 'vue';
import PlaceInfo from './PlaceInfo.vue';
let router = useRouter()
const size = ref < 'default' | 'large' | 'small' > ('default')
const createTime = ref('')
const options = [
    {
        value: '0',
        label: '0',
    },
    {
        value: '1',
        label: '1',
    },
    {
        value: '2',
        labe2: '2',
    }
]
let placeInfo = ref({
    id: router.currentRoute.value.query.id,
    parkingNum: '',
    spaceNum: '',
    area: '',
    createTime: '',
    notes: ''
})
let formRef = ref(null) //表单dom对象
let formRules = {
    parkingNum: [
        { required: true, message: '请输入停车场编号', trigger: 'blur' }
    ],
    spaceNum: [
        { required: true, message: '请输入车位编号', trigger: 'blur' }
    ],
    area: [
        { required: true, message: '请输入停车场面积', trigger: 'blur' }
    ]
}
onBeforeMount(async () => {
    if (placeInfo.value.id) {
        let resp = await http.get(`/placeInfo/get/${placeInfo.value.id}`)
        placeInfo.value = resp.data
    }
})
async function save(formRef) {
    formRef.validate(async function (valid) {
        if (valid) {
            let path = placeInfo.value.id ? '/placeInfo/update' : '/placeInfo/add'
            let tip = placeInfo.value.id ? '修改' : '保存'
            let resp = await http.post(path, placeInfo.value)
            if (resp.code == 200) {
                ElMessageBox.alert(tip + '账户成功', tip + '账户', {
                    confirmButtonText: 'OK'
                })
                router.go(-1)
            } else {

            }
        }
    })
}
function cancel() {
    router.go(-1)
}

</script>
<style lang="css" scoped>
.form {
    width: 400px;
    margin: 0 auto;
}

.el-form-item__label {
    width: 120px;
}
</style>